<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.*"%>
<%@page import="javabean.*"%>
<%@page import="javabean.book.*"%>
<%@page import="javabean.user.*"%>
<!DOCTYPE html>
<html lang="zh-cn">
	<%
		String userId = (String) session.getAttribute("uid");
		boolean isRole = false;
		if(userId!=null){
			isRole = (Boolean)request.getAttribute("isRole");
		}
		List<BookTag> bookTag = new ArrayList<BookTag>() ; //图书分类标签
		List<Book> allBook = (List)request.getAttribute("allBook");	//所有的书
		List<Book> all = (List)request.getAttribute("userbook");	//我拥有的书
		List<Book> dAll = (List)request.getAttribute("dAll");	//我借的书
		User user = (User)request.getAttribute("user");	//用户对象
		String uid = user.getUid();
		String uname = ParseDouble.parseNullToStr(user.getUname());
		String sex = ParseDouble.parseNullToStr(user.getSex());
		String pic = ParseDouble.parseNullToStr(user.getPic());
		long credit = user.getCredit();
		long activity = user.getActivity();
		long contribution = user.getContribution();
		long favorability = user.getFavorability();
		int coumple = ParseDouble.countCompleX(credit,activity,contribution,favorability);	//综合等级
		String showName = "";
		if(uname!=null){
			showName = uname ;
		}else{
			showName = uid ;
		}
		
		//遍历书籍，根据isCheck进行分类
		List<Book> pass = new ArrayList<Book>();
		List<Book> uncheck = new ArrayList<Book>();
		List<Book> unpass = new ArrayList<Book>();
		List<Book> isdebit = new ArrayList<Book>();
		if(uid.equals(userId) && isRole){
			Iterator<Book> iter = allBook.iterator() ;
			while(iter.hasNext()){
				Book book = (Book)iter.next();
				int isCheck = book.getIsCheck();
				if(isCheck==1){
					pass.add(book);
				}else if(isCheck==0){
					uncheck.add(book);
				}else if(isCheck==2){
					unpass.add(book);
				}
			}
			bookTag = (List)request.getAttribute("bookTag");
		}else if(uid.equals(userId)){
			Iterator<Book> iter = all.iterator() ;
			while(iter.hasNext()){
				Book book = (Book)iter.next();
				int isCheck = book.getIsCheck();
				String debit = book.getDebit();
				if(isCheck==1 && (debit==null || "".equals(debit))){
					pass.add(book);
				}else if(isCheck==0){
					uncheck.add(book);
				}else if(isCheck==2){
					unpass.add(book);
				}
				if(debit!=null && !"".equals(debit)){
					isdebit.add(book);
				}
			}
		}else{
			Iterator<Book> iter = all.iterator() ;
			while(iter.hasNext()){
				Book book = (Book)iter.next();
				int isCheck = book.getIsCheck();
				int quantity = book.getQuantity();
				if(isCheck==1 && quantity>0){
					pass.add(book);
				}
			}
		}
		
		
		//System.out.println(pass.size()+" "+uncheck.size()+" "+unpass.size()+" "+isdebit.size()+" "+dAll.size());
		
	%>
    <head>
    	<title><%=showName %>的个人中心</title>
    	<meta charset="utf-8">
        <link rel="stylesheet" type="text/css" href="/bookcrossing/css/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="/bookcrossing/css/main.css">
        <link rel="stylesheet" type="text/css" href="/bookcrossing/css/user.css">
        <link rel="shortcut icon" type="image/png" href="/bookcrossing/img/favicon.png" />
	</head>
	<body>
		<jsp:include page="../public/head.jsp"></jsp:include>
		<div class="modal fade" id="book-info-dialog-box">
	    	<div class="modal-dialog">
	    		<div class="modal-content">
	    			<div class="modal-header">
	    				<p class="title">还书喽</p>
	    			</div>
	    			<form class="form-horizontal" id="send-tips-form">
		    			<div class="modal-body">
		    				<div class="form-group">
		    					<label for="receiver" class="col-sm-2 control-label">书主:</label>
							    <div class="col-sm-9">
							      <input type="text" class="form-control receiver input-sm" id="receiver" name="receiver" " readonly >
							    </div>
		    				</div>
		    				<div class="form-group">
		    					<label for="tcontents" class="col-sm-2 control-label">内容:</label>
							    <div class="col-sm-9">
							      <textarea class="form-control tcontents input-sm" id="tcontents" name="tcontents" placeholder="还可以说点感谢的话哦~" rows="4" ></textarea>
							    </div>
		    				</div>
		    			</div>
		    			<div class="modal-footer">
		    				<button type="submit" class="btn btn-info btn-sm submit-btn">发送</button>
		    				<button type="button" class="btn btn-warning btn-sm cancel-btn" data-dismiss="modal">取消</button>
		    			</div>
	    			</form>
	    		</div>
	    	</div>
	    </div>
		<div class="container user-profile-container">
			<div class="content-top">
				<a href="javascript:history.go(-1);" class="go-back"><< 返回上一页</a>
			</div>
			<div class="content-main">
				<div class="u-p-content tab-content">
				<%if(uid.equals(userId) && isRole){ %>
					<div class="tab-pane fade in active" id="user-book-pass">
					<p class="u-b-title">审核通过图书</p>
					<%
						if(pass.size()==0){
					%>
						<div class="alert alert-warning no-book">木有哦~</div>
					<%
						}
						Iterator<Book> passIter = pass.iterator() ;
						while(passIter.hasNext()){
							Book book = (Book)passIter.next();
							long  bid = book.getBid() ;
							String bname = book.getBname() ;
							String author = book.getAuthor() ;
							String picurl = (book.getPicurl()==null)?"book.jpg":book.getPicurl() ;
							String cutBname = bname;
							byte[] s = cutBname.getBytes();
							byte[] ss = author.getBytes();
							if(s.length>18){
								cutBname = new String(s,0,16)+"...";
							}
							if(ss.length>18){
								author = new String(ss,0,16)+"...";
							}
					%>
						<div class="book-info">
							<div class="book-pic-wrap">
								<img src="/bookcrossing/img/book/<%=picurl %>"/>
								<div class="control">
									<a href="javascript:void(0)" class="check-unpass" title="不通过" data-bid="<%=bid %>"><apan class="glyphicon glyphicon-ban-circle"></apan></a>
									<a href="javascript:void(0)" class="del" title="删除" data-bid="<%=bid %>" data-pic="<%=picurl %>"><apan class="glyphicon glyphicon-trash"></apan></a>
								</div>
							</div>
							<p class="book-title"><a href="/bookcrossing/book?bid=<%=bid %>" target="_blank" title="<%=bname %>"><%=cutBname %></a></p>
							<p class="book-author"><%=author %></p>
						</div>
					<%} %>
					</div>
					<div class="tab-pane fade" id="user-book-uncheck">
					<p class="u-b-title">待审核图书</p>
					<%
						if(uncheck.size()==0){
					%>
						<div class="alert alert-warning no-book">木有哦~</div>
					<%
						}
						Iterator<Book> uncheckIter = uncheck.iterator() ;
						while(uncheckIter.hasNext()){
							Book book = (Book)uncheckIter.next();
							long  bid = book.getBid() ;
							String bname = book.getBname() ;
							String author = book.getAuthor() ;
							String picurl = (book.getPicurl()==null)?"book.jpg":book.getPicurl() ;
							String cutBname = bname;
							byte[] s = cutBname.getBytes();
							byte[] ss = author.getBytes();
							if(s.length>18){
								cutBname = new String(s,0,16)+"...";
							}
							if(ss.length>18){
								author = new String(ss,0,16)+"...";
							}
					%>
						<div class="book-info">
							<div class="book-pic-wrap">
								<img src="/bookcrossing/img/book/<%=picurl %>"/>
								<div class="control">
									<a href="javascript:void(0)" class="check-pass" title="通过" data-bid="<%=bid %>" data-pic="<%=picurl %>"><apan class="glyphicon glyphicon-ok"></apan></a>
									<a href="javascript:void(0)" class="check-unpass" title="不通过" data-bid="<%=bid %>"><apan class="glyphicon glyphicon-ban-circle"></apan></a>
								</div>
							</div>
							<p class="book-title"><a href="/bookcrossing/book?bid=<%=bid %>" target="_blank" title="<%=bname %>"><%=cutBname %></a></p>
							<p class="book-author"><%=author %></p>
						</div>
					<%} %>
					</div>
					<div class="tab-pane fade" id="user-book-unpass">
					<p class="u-b-title">审核不通过图书</p>
					<%
						if(unpass.size()==0){
					%>
						<div class="alert alert-warning no-book">木有哦~</div>
					<%
						}
						Iterator<Book> unpassIter = unpass.iterator() ;
						while(unpassIter.hasNext()){
							Book book = (Book)unpassIter.next();
							long  bid = book.getBid() ;
							String bname = book.getBname() ;
							String author = book.getAuthor() ;
							String picurl = (book.getPicurl()==null)?"book.jpg":book.getPicurl() ;
							String cutBname = bname;
							byte[] s = cutBname.getBytes();
							byte[] ss = author.getBytes();
							if(s.length>18){
								cutBname = new String(s,0,16)+"...";
							}
							if(ss.length>18){
								author = new String(ss,0,16)+"...";
							}
					%>
						<div class="book-info">
							<div class="book-pic-wrap">
								<img src="/bookcrossing/img/book/<%=picurl %>"/>
								<div class="control">
									<a href="javascript:void(0)" class="check-pass" title="通过" data-bid="<%=bid %>" data-pic="<%=picurl %>"><apan class="glyphicon glyphicon-ok"></apan></a>
								</div>
							</div>
							<p class="book-title"><a href="/bookcrossing/book?bid=<%=bid %>" target="_blank" title="<%=bname %>"><%=cutBname %></a></p>
							<p class="book-author"><%=author %></p>
						</div>
					<%} %>
					</div>
					<div class="tab-pane fade" id="book-tag">
						<p class="u-b-title">图书类别</p>
						<form id="book-tag-add-form" class="book-tag-add">
							<div class="input-group col-lg-4">
								<input type="text" name="tagName" class="form-control input-sm" placeholder="添加新分类"/>
								<span class="input-group-btn">
									<button class="book-tag-add-btn btn btn-success btn-sm">添加</button>
								</span>
							</div>
						</form>
						<ul class="book-tag-list">
						<%
							Iterator<BookTag> tagIter = bookTag.iterator() ;
							while(tagIter.hasNext()){
								BookTag book_tag = (BookTag)tagIter.next();
    							String tagName = book_tag.getTagname();
    							Long readCount = book_tag.getReadcount();
    							List<Book> book = book_tag.getBook();
						%>
							<li>
								<div class="tag-name-wrap">
									<span class="label label-info"><%=tagName %></span>
									<input type="text" name="tagname" value="<%=tagName %>" class="tag-name-input"/>
								</div>
								<p>共 <a href="/bookcrossing/search?type=<%=tagName %>" class="light"><%=book.size() %></a> 本书</p>
								<p>点击量: <span class="light"> <%=readCount %> </span></p>
							</li>
						<%} %>
						</ul>
					</div>
					<div class="tab-pane fade" id="user-twt">
						<p class="u-b-title">说说管理</p>
					</div>
				<%}else if(uid.equals(userId)){ %>
					<div class="tab-pane fade in active" id="user-book-pass">
					<p class="u-b-title">现有图书</p>
					<%
						if(pass.size()==0){
					%>
						<div class="alert alert-warning no-book">木有哦~</div>
					<%
						}
						Iterator<Book> passIter = pass.iterator() ;
						while(passIter.hasNext()){
							Book book = (Book)passIter.next();
							long  bid = book.getBid() ;
							String bname = book.getBname() ;
							String author = book.getAuthor() ;
							String picurl = (book.getPicurl()==null)?"book.jpg":book.getPicurl() ;
							String cutBname = bname;
							byte[] s = cutBname.getBytes();
							byte[] ss = author.getBytes();
							if(s.length>18){
								cutBname = new String(s,0,16)+"...";
							}
							if(ss.length>18){
								author = new String(ss,0,16)+"...";
							}
					%>
						<div class="book-info">
							<div class="book-pic-wrap">
								<img src="/bookcrossing/img/book/<%=picurl %>"/>
								<div class="control">
									<a href="/bookcrossing/book/edit?bid=<%=bid %>" class="edit" title="编辑"><apan class="glyphicon glyphicon-edit"></apan></a>
									<a href="javascript:void(0)" class="del" title="删除" data-bid="<%=bid %>" data-pic="<%=picurl %>"><apan class="glyphicon glyphicon-trash"></apan></a>
								</div>
							</div>
							<p class="book-title"><a href="/bookcrossing/book?bid=<%=bid %>" target="_blank" title="<%=bname %>"><%=cutBname %></a></p>
							<p class="book-author"><%=author %></p>
						</div>
					<%} %>
					</div>
					<div class="tab-pane fade" id="user-book-uncheck">
					<p class="u-b-title">未审核图书</p>
					<%
						if(uncheck.size()==0){
					%>
						<div class="alert alert-warning no-book">木有哦~</div>
					<%
						}
						Iterator<Book> uncheckIter = uncheck.iterator() ;
						while(uncheckIter.hasNext()){
							Book book = (Book)uncheckIter.next();
							long  bid = book.getBid() ;
							String bname = book.getBname() ;
							String author = book.getAuthor() ;
							String picurl = (book.getPicurl()==null)?"book.jpg":book.getPicurl() ;
							String cutBname = bname;
							byte[] s = cutBname.getBytes();
							byte[] ss = author.getBytes();
							if(s.length>18){
								cutBname = new String(s,0,16)+"...";
							}
							if(ss.length>18){
								author = new String(ss,0,16)+"...";
							}
					%>
						<div class="book-info">
							<div class="book-pic-wrap">
								<img src="/bookcrossing/img/book/<%=picurl %>"/>
								<div class="control">
									<a href="/bookcrossing/book/edit?bid=<%=bid %>" class="edit" title="编辑"><apan class="glyphicon glyphicon-edit"></apan></a>
									<a href="javascript:void(0)" class="del" title="删除" data-bid="<%=bid %>" data-pic="<%=picurl %>"><apan class="glyphicon glyphicon-trash"></apan></a>
								</div>
							</div>
							<p class="book-title"><a href="/bookcrossing/book?bid=<%=bid %>" target="_blank" title="<%=bname %>"><%=cutBname %></a></p>
							<p class="book-author"><%=author %></p>
						</div>
					<%} %>
					</div>
					<div class="tab-pane fade" id="user-book-unpass">
					<p class="u-b-title">审核不通过图书</p>
					<%
						if(unpass.size()==0){
					%>
						<div class="alert alert-warning no-book">木有哦~</div>
					<%
						}
						Iterator<Book> unpassIter = unpass.iterator() ;
						while(unpassIter.hasNext()){
							Book book = (Book)unpassIter.next();
							long  bid = book.getBid() ;
							String bname = book.getBname() ;
							String author = book.getAuthor() ;
							String picurl = (book.getPicurl()==null)?"book.jpg":book.getPicurl() ;
							String cutBname = bname;
							byte[] s = cutBname.getBytes();
							byte[] ss = author.getBytes();
							if(s.length>18){
								cutBname = new String(s,0,16)+"...";
							}
							if(ss.length>18){
								author = new String(ss,0,16)+"...";
							}
					%>
						<div class="book-info">
							<div class="book-pic-wrap">
								<img src="/bookcrossing/img/book/<%=picurl %>"/>
								<div class="control">
									<%--<a href="/bookcrossing/book/edit?bid=<%=bid %>" class="edit" title="编辑"><apan class="glyphicon glyphicon-edit"></apan></a>--%>
									<a href="javascript:void(0)" class="del" title="删除" data-bid="<%=bid %>" data-pic="<%=picurl %>"><apan class="glyphicon glyphicon-trash"></apan></a>
								</div>
							</div>
							<p class="book-title"><a href="/bookcrossing/book?bid=<%=bid %>" target="_blank" title="<%=bname %>"><%=cutBname %></a></p>
							<p class="book-author"><%=author %></p>
						</div>
					<%} %>
					</div>
					<div class="tab-pane fade" id="user-book-isdebit">
					<p class="u-b-title">被借图书</p>
					<%
						if(isdebit.size()==0){
					%>
						<div class="alert alert-warning no-book">木有哦~</div>
					<%
						}
						Iterator<Book> isdebitIter = isdebit.iterator() ;
						while(isdebitIter.hasNext()){
							Book book = (Book)isdebitIter.next();
							long  bid = book.getBid() ;
							String bname = book.getBname() ;
							String author = book.getAuthor() ;
							String picurl = (book.getPicurl()==null)?"book.jpg":book.getPicurl() ;
							String cutBname = bname;
							byte[] s = cutBname.getBytes();
							byte[] ss = author.getBytes();
							if(s.length>18){
								cutBname = new String(s,0,16)+"...";
							}
							if(ss.length>18){
								author = new String(ss,0,16)+"...";
							}
					%>
						<div class="book-info">
							<div class="book-pic-wrap">
								<img src="/bookcrossing/img/book/<%=picurl %>"/>
								<div class="control">
									<a href="/bookcrossing/book/edit?bid=<%=bid %>" class="edit" title="编辑"><apan class="glyphicon glyphicon-edit"></apan></a>
									<a href="javascript:void(0)" class="del" title="删除" data-bid="<%=bid %>" data-pic="<%=picurl %>"><apan class="glyphicon glyphicon-trash"></apan></a>
								</div>
							</div>
							<p class="book-title"><a href="/bookcrossing/book?bid=<%=bid %>" target="_blank" title="<%=bname %>"><%=cutBname %></a></p>
							<p class="book-author"><%=author %></p>
						</div>
					<%} %>
					</div>
					<div class="tab-pane fade" id="user-book-debit-other">
					<p class="u-b-title">我借的图书</p>
					<%
						if(dAll.size()==0){
					%>
						<div class="alert alert-warning no-book">木有哦~</div>
					<%
						}
						Iterator<Book> dAllIter = dAll.iterator() ;
						while(dAllIter.hasNext()){
							Book book = (Book)dAllIter.next();
							long  bid = book.getBid() ;
							String bname = book.getBname() ;
							String author = book.getAuthor() ;
							String picurl = (book.getPicurl()==null)?"book.jpg":book.getPicurl() ;
							String belong = book.getBelong();
							String cutBname = bname;
							byte[] s = cutBname.getBytes();
							byte[] ss = author.getBytes();
							if(s.length>18){
								cutBname = new String(s,0,16)+"...";
							}
							if(ss.length>18){
								author = new String(ss,0,16)+"...";
							}
					%>
						<div class="book-info">
							<div class="book-pic-wrap">
								<img src="/bookcrossing/img/book/<%=picurl %>"/>
								<div class="control">
									<a href="javascript:void(0)" class="return" title="还书" data-bid="<%=bid %>" data-belong="<%=belong %>"><apan class="glyphicon glyphicon-send"></apan></a>
								</div>
							</div>
							<p class="book-title"><a href="/bookcrossing/book?bid=<%=bid %>" target="_blank" title="<%=bname %>"><%=cutBname %></a></p>
							<p class="book-author"><%=author %></p>
						</div>
					<%} %>
					</div>
					<div class="tab-pane fade" id="user-twt">
						<p class="u-b-title">个人说说</p>
					</div>
				<%}else{ %>
					<div class="tab-pane fade in active" id="user-book-pass">
						<p class="u-b-title">TA 的图书</p>
						<%
							if(pass.size()==0){
						%>
							<div class="alert alert-warning no-book">木有哦~</div>
						<%
							}
							Iterator<Book> passIter = pass.iterator() ;
							while(passIter.hasNext()){
								Book book = (Book)passIter.next();
								long  bid = book.getBid() ;
								String bname = book.getBname() ;
								String author = book.getAuthor() ;
								String picurl = (book.getPicurl()==null)?"book.jpg":book.getPicurl() ;
								String cutBname = bname;
								byte[] s = cutBname.getBytes();
								byte[] ss = author.getBytes();
								if(s.length>18){
									cutBname = new String(s,0,16)+"...";
								}
								if(ss.length>18){
									author = new String(ss,0,16)+"...";
								}
						%>
							<div class="book-info">
								<div class="book-pic-wrap">
									<a href="/bookcrossing/book?bid=<%=bid %>"><img src="/bookcrossing/img/book/<%=picurl %>"/></a>
								</div>
								<p class="book-title"><a href="/bookcrossing/book?bid=<%=bid %>" target="_blank" title="<%=bname %>"><%=cutBname %></a></p>
								<p class="book-author"><%=author %></p>
							</div>
						<%} %>
					</div>
					<div class="tab-pane fade" id="user-twt">
						<p class="u-b-title">TA 的说说</p>
					</div>
				<%} %>
				</div>
				
				<div class="right">
		      		<div >
			       		<div class="right-top"></div>
			       		<div class="right-content-wrap">
			        		<div class="right-content">
			        			<div class="user-pic">
			        				<div class="pic-wrap">
			        					<img src="/bookcrossing/img/user/<%=pic %>" alt="头像"/>
			        				</div>
			        				<ul class="level">
			        					<li><span class="l-label">信用: </span><span class="nb credit"><%=credit %></span></li>
			        					<li><span class="l-label">活跃: </span><span class="nb activity"><%=(long)Math.sqrt(activity) %></span></li>
			        					<li><span class="l-label">贡献: </span><span class="nb contribution"><%=contribution %></span></li>
			        					<li><span class="l-label">好感: </span><span class="nb favorability"><%=favorability %></span></li>
			        					<li><span class="l-label">综合: </span><span class="nb coumple"><%=coumple %></span></li>
			        				</ul>
			        			</div>
			        			
			        			<ul id="u-b-tab" class="nav">
			        			<%if(uid.equals(userId) && isRole){%>
			        				<li>
			        					<a href="javascript:void(0)" id="bookTabDrop" >图书管理</a>
			        					<ul class="sub-menu">
			        						<li class="active">
			        							<a href="#user-book-pass" data-toggle="tab">审核通过图书</a>
			        						</li>
			        						<li>
			        							<a href="#user-book-uncheck" data-toggle="tab">待审核图书</a>
			        						</li>
			        						<li>
			        							<a href="#user-book-unpass" data-toggle="tab">审核不通过图书</a>
			        						</li>
			        						<li>
			        							<a href="#book-tag" data-toggle="tab">图书类别</a>
			        						</li>
			        					</ul>
			        				</li>
			        				<li class="no-sub">
			        					<a href="#user-twt" data-toggle="tab">说说管理</a>
			        				</li>
			        			<%}else if(uid.equals(userId)){ %>
			        				<li>
			        					<a href="javascript:void(0)" id="bookTabDrop" >个人图书</a>
			        					<ul class="sub-menu">
			        						<li class="active">
			        							<a href="#user-book-pass" data-toggle="tab">现有图书</a>
			        						</li>
			        						<li>
			        							<a href="#user-book-uncheck" data-toggle="tab">未审核图书</a>
			        						</li>
			        						<li>
			        							<a href="#user-book-unpass" data-toggle="tab">审核不通过图书</a>
			        						</li>
			        						<li>
			        							<a href="#user-book-isdebit" data-toggle="tab">被借图书</a>
			        						</li>
			        						<li>
			        							<a href="#user-book-debit-other" data-toggle="tab">我借的图书</a>
			        						</li>
			        					</ul>
			        				</li>
			        				<li class="no-sub">
			        					<a href="#user-twt" data-toggle="tab">个人说说</a>
			        				</li>
			        			<%}else{ %>
			        				<li class="no-sub active">
			        					<a href="#user-book-pass" data-toggle="tab">TA 的图书</a>
			        				</li>
			        				<li class="no-sub">
			        					<a href="#user-twt" data-toggle="tab">TA 的说说</a>
			        				</li>
			        			<%} %>
			        			</ul>
			        			
			        		</div>
			        	</div>
			      		<div class="right-bottom"></div>
		      		</div>
	      		</div>
	      		<div class="toTop-wrap">
		       		<a href="javascript:;" id="toTop" title="返回顶部"></a>
		       	</div>
			</div>
		</div>
		<jsp:include page="../public/foot.jsp"></jsp:include>
		<script src="/bookcrossing/js/jquery-1.9.1.min.js" type="text/javascript"></script>
        <script src="/bookcrossing/js/bootstrap.min.js" type="text/javascript" ></script>
        <script src="/bookcrossing/js/common.js" type="text/javascript" ></script>
        <script src="/bookcrossing/js/user-profile.js" type="text/javascript" ></script>
	</body>